<template>
  <el-form-item :label="label" :required="required">
    <el-select
      v-model="modelValue"
      :options="options"
      :multiple="multiple"
      :clearable="clearable"
      :placeholder="placeholder"
      :disabled="disabled"
      @change="handleChange"
    />
  </el-form-item>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

interface Option {
  label: string
  value: string | number
  disabled?: boolean
}

export default defineComponent({
  name: 'EnumControl',
  props: {
    modelValue: {
      type: [String, Number, Array],
      default: ''
    },
    label: {
      type: String,
      default: ''
    },
    required: {
      type: Boolean,
      default: false
    },
    options: {
      type: Array as () => Option[],
      required: true
    },
    multiple: {
      type: Boolean,
      default: false
    },
    clearable: {
      type: Boolean,
      default: true
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  emits: ['update:modelValue'],
  setup(props, { emit }) {
    const handleChange = (value: any) => {
      emit('update:modelValue', value)
    }

    return {
      handleChange
    }
  }
})
</script>